package com.cloud.haiyan_file;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.PostConstruct;
import java.util.TimeZone;

@EnableTransactionManagement
@EnableSwagger2
@EnableDiscoveryClient
@EnableFeignClients("com.cloud.haiyan_commons.feign")
@MapperScan("com.cloud.haiyan_file.mapper")
@SpringBootApplication(exclude = MongoAutoConfiguration.class)
@ComponentScan(basePackages = {
        "com.cloud.haiyan_commons.feign",
        "com.cloud.haiyan_commons.config.redis",
        "com.cloud.haiyan_file.config",
        "com.cloud.haiyan_utils",
        "com.cloud.haiyan_file.util",
        "com.cloud.haiyan_file.restapi",
        "com.cloud.haiyan_file.service"})

public class HaiyanFileApplication {

    public static void main(String[] args) {
        SpringApplication.run(HaiyanFileApplication.class, args);
    }
    /**
     * 设置时区
     */
    @PostConstruct
    void setDefaultTimezone() {
        TimeZone.setDefault(TimeZone.getTimeZone("Asia/Shanghai"));
    }

    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                //配置允许跨域访问的路径
                registry.addMapping("/**/**")
                        .allowedOrigins("*")
                        .allowedMethods("*")
                        .allowedHeaders("*")
                        .allowCredentials(true)
                        .exposedHeaders("")
                        .maxAge(3600);
            }
        };
    }


}
